import axios from 'axios'

const service = axios.create({
  baseURL: `${import.meta.env.VITE_API_URL}/api`,
  timeout: 5000,
})
// 请求拦截器
service.interceptors.request.use(
  (config) => {
    // config.headers.token = '7cac63c6-9dd3-4d28-9c5d-44bf1dc8405a'
    return config
  },
  (error) => {
    return Promise.reject(error)
  },
)
// 响应拦截器
service.interceptors.response.use(
  (response) => {
    const { code, data, msg: message } = response.data
    if (code === 1) {
      return data
    } else {
      return Promise.reject(new Error(message))
    }
  },
  (error) => {
    return Promise.reject(error)
  },
)

export default service
